<!doctype html>
<html lang="en">
	<head>
	    <meta charset="utf-8">
	    <title>发送病历</title>
	    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
	    <meta name="apple-mobile-web-app-capable" content="yes">
	    <meta name="apple-mobile-web-app-status-bar-style" content="black">
	    <link href="css/mui.min.css" rel="stylesheet"/>
	    <link rel="stylesheet" type="text/css" href="css/mui.picker.min.css" />
	    <link rel="stylesheet" href="css/grandeHealth.css"/>
	    <style>		
			.mui-search {width: 68%;float: left;}
			input[type=search]{background: #fff;border: 1px solid #ccc;height: 45px;border: 0;margin-bottom: 5px;}
			.mui-search .mui-placeholder {line-height: 45px;}
			.Yescfim,#screen{width: 15%;font-size:18px;border-radius: 5px;height: 45px;padding: 0;}
			.Yescfim{margin-left: 5px;}
			#screen{float: right;color: #39ABE7;border: 1px solid #39ABE7;}
			.mui-table-view li{text-align: center;line-height: 40px;border-bottom: 1px solid #eee;}
			.mui-table-view li div{height: 40px;}
			.name{text-align: left;}
			.viewRecord{color: #2F9CDC;}
			.sends{background: #2F9CDC;border-radius: 10px;color: #fff;}
			#pullrefresh{margin-top: 50px;}
			.mui-media-body{overflow: hidden;background: #fff;width:100%;border-bottom:1px solid #DDDDE0;padding: 11px 15px;color: #999;}
	    	#recordList .kaoheDate{text-align: right;}
	    	#recordList .viewRecord{text-align: right;margin: 0 7% 0 25.5%;border-radius:10px;text-align:center;border:1px solid #2F9CDC;}
	    </style>
	</head>
	<body>
		<!--<header>class="mui-bar mui-bar-nav" style="display: block;height: 64px;padding-top:20px">
	      <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" id="goBack"></a>
	    </header>-->
	    
		<div class="mui-content">
			<div class="mui-indexed-list">
				<div class="mui-indexed-list-search mui-input-row mui-search">
					<input type="search" id="searchInput" value="" class="inputValue mui-input-clear mui-indexed-list-search-input" placeholder="请输入患者姓名搜索">
				</div>
				<button class="Yescfim" id="search">搜索</button>
				<button id='screen' class="screen" data-options='{"type":"date","beginYear":1950,"endYear":2050}'>筛选</button>
				
				<div id="resultDate"></div>
			</div>
		</div>

		<!--下拉刷新容器-->
		<div id="infoAlls">
			<div class="mui-media-body" id="tishi" style="display: none;"></div>
		</div>
	    <div class="mui-scroll-wrapper" id="pullrefresh">
      		<div class="mui-scroll">
		        <!-- 数据列表 -->
		        <ul class="mui-table-view" id="recordList">		        	
		        	<!--<li class="mui-table-view-cell mui-media mui-row">
			            <div class="name mui-col-sm-6 mui-col-xs-6">15647893124</div>
			            <div class="kaoheDate mui-col-sm-6 mui-col-xs-6">2017-07-31</div>
			            <div class="viewRecord mui-col-sm-5 mui-col-xs-5">查看咨询建议</div>
			            <div class="sends mui-col-sm-3 mui-col-xs-3">发送</div>
			        </li>-->
		 		</ul>
      		</div>
	    </div>
		<script src="js/jquery-1.7.2.min.js"></script>
		<script src="js/mui.min.js"></script>
		<script src="js/grandeHealth.js"></script>
		<script src="js/mui.picker.min.js"></script>
		<script src="js/medicalRecord.js"></script>
		<script>
			var arry = {};
			var count = 2;
			var totalNumber;//总条数
			var crtdat = '';
//			var XHDOC_APP_USRGUID = '174BD3D5879C3BF0E050007F010077DC';
			/*
			 * keydown调用
			 */
			$('input[type=search]').keydown(function(event){
				selectEarchDoc();//调用搜索方法			
			})
			
			
			/*
			 * 搜索病历按钮
			 */
			mui("body").on("tap", ".Yescfim", function() {
				var drugName = $(".inputValue").val();
			    if(!drugName){
			      mui.toast("搜索不能为空");
			      return false;
			    }
				selectEarchDoc();	
			});
			
			
			/*
			 * 筛选病历
			 */
			
			(function($) {
				$.init();
				var screen = $('#screen')[0];
				var btns = $('.screen');
				btns.each(function(i, btn) {
					btn.addEventListener('tap', function() {
						var optionsJson = this.getAttribute('data-options') || '{}';
						var options = JSON.parse(optionsJson);
						var id = this.getAttribute('id');
						var picker = new $.DtPicker(options);
						document.activeElement.blur();//关闭软键盘
						picker.show(function(rs) {
							drugName = document.getElementById('searchInput').value;//输入框值
							crtdat = rs.text;
							picker.dispose();
							//验证特殊字符
							if(drugName.indexOf("'")>-1 || drugName.indexOf("\"")>-1 || drugName.indexOf("=")>-1 || drugName.indexOf("-")>-1 || drugName.indexOf("+")>-1 || drugName.indexOf("*")>-1 || drugName.indexOf("%")>-1 || drugName.indexOf("&")>-1){
								document.getElementById('tishi').innerHTML="请勿包含特殊字符！！";//放值的框
								return;
							}
							var webUrl = XHDOC_WEBBASE + "dtcasehistory/getprofileDetails?&pageSize=10&name="+drugName+"&docguid="+XHDOC_APP_USRGUID+"&crtdat="+crtdat;
							
							try {
							  	$.ajax({
								    url: webUrl,
								    type: "POST",
									async: false,
									timeout:8000,
									success: function(data) {
										data = data.trim();
						  				data = JSON.parse(data)
										if(data.code == 000){
									    	arry = data.data;
									    	document.getElementById('recordList').innerHTML = '';
									    	if(arry.parameterType == ""){
												document.getElementById('tishi').innerHTML = '没有搜索到相关患者';
									    		document.getElementById('tishi').style.display = 'block';
									    		document.getElementById('pullrefresh').style.marginTop = '155px';
									    		document.getElementById('recordList').style.display = 'none';
									    	}else{
									    		for(var i = 0 ; i < arry.parameterType.length; i ++){
									    			var dateTime = arry.parameterType[i].crtdat;
													var mydate=dateTime.substr(0,10);
													var li = document.createElement('li');
										            li.className = 'mui-table-view-cell mui-media mui-row';
													li.innerHTML = 
												             	'<div name="'+arry.parameterType[i].zhand+'" class="name mui-col-sm-6 mui-col-xs-6">'+arry.parameterType[i].name+'</div>'+
													            '<div name="'+arry.parameterType[i].birthday+'" class="kaoheDate mui-col-sm-6 mui-col-xs-6">'+mydate+'</div>'+
													            '<div id="'+arry.parameterType[i].zhand+'" name="'+arry.parameterType[i].guid+'" class="viewRecord mui-col-sm-5 mui-col-xs-5">查看咨询建议</div>'+
													            '<div id="'+arry.parameterType[i].age+'" name="'+arry.parameterType[i].sex+'" class="sends mui-col-sm-3 mui-col-xs-3">发送</div>';	
					            
										            document.getElementById('recordList').appendChild(li);
										    	}
									    		document.getElementById('recordList').style.display = 'block';
									    		document.getElementById('tishi').style.display = 'none';
									    		document.getElementById('pullrefresh').style.marginTop = '115px';
									    	}
									    	
									    }else if(data.code == 001){
									    	mui.toast('请求出错'); 
										}
									},
									error: function(xhr, textStatus, error) {						
								  		if(textStatus == "error")
										mui.toast('请检查网络连接');
								  	}
							  	});
			
							} catch(e) {
							  mui.toast("请检查网络连接");
							
						   	}
					
						});
					}, false);
				});
			})(mui);
			
			
			/*
			 * 输入框内容改变
			 */		
			function selectEarchDoc(){
				var drugName = $('input[type="search"]').val();//输入框值
				//验证特殊字符
				if(drugName.indexOf("'")>-1 || drugName.indexOf("\"")>-1 || drugName.indexOf("=")>-1 || drugName.indexOf("-")>-1 || drugName.indexOf("+")>-1 || drugName.indexOf("*")>-1 || drugName.indexOf("%")>-1 || drugName.indexOf("&")>-1){
					document.getElementById('tishi').innerHTML="请勿包含特殊字符！！";//放值的框
					return;
				}
				
				if(drugName.trim() != ''){

					drugName = encodeURIComponent(drugName.trim());				
					var webUrl = XHDOC_WEBBASE + "dtcasehistory/getprofileDetails?&pageSize=10&name="+drugName+"&docguid="+XHDOC_APP_USRGUID+"&crtdat="+crtdat;
					try {
					  	$.ajax({
						    url: webUrl,
						    type: "POST",
							async: false,
							timeout:8000,
							success: function(data) {
								data = data.trim();
				  				data = JSON.parse(data)
								if(data.code == 000){
							    	arry = data.data;
							    	$('.mui-table-view').html('');						    	
							    	if(arry.parameterType == ""){
							    		$('#tishi').html('没有搜索到相关患者').show();
							    		document.getElementById('tishi').style.display = 'block';
							    		document.getElementById('pullrefresh').style.marginTop = '155px';
							    	}else{
							    		for(var i = 0 ; i < arry.parameterType.length; i ++){
							    			var dateTime = arry.parameterType[i].crtdat;
											var mydate=dateTime.substr(0,10); 
								    		var duglhtml = 											
													'<li class="mui-table-view-cell mui-media mui-row">'+
											             '<div name="'+arry.parameterType[i].zhand+'" class="name mui-col-sm-6 mui-col-xs-6">'+arry.parameterType[i].name+'</div>'+
											            '<div name="'+arry.parameterType[i].birthday+'" class="kaoheDate mui-col-sm-6 mui-col-xs-6">'+mydate+'</div>'+
											            '<div id="'+arry.parameterType[i].zhand+'" name="'+arry.parameterType[i].guid+'" class="viewRecord mui-col-sm-5 mui-col-xs-5">查看咨询建议</div>'+
											            '<div id="'+arry.parameterType[i].age+'" name="'+arry.parameterType[i].sex+'" class="sends mui-col-sm-3 mui-col-xs-3">发送</div>';	
											        '</li>';			        
											$('#recordList').append(duglhtml);
								    	}
							    		document.getElementById('tishi').style.display = 'none';
							    		document.getElementById('pullrefresh').style.marginTop = '115px';
							    		document.getElementById('recordList').style.display = 'block';
							    	}
							    	
							    }else if(data.code == 001){
							    	mui.toast('请求出错'); 
								}
							},
							error: function(xhr, textStatus, error) {						
						  		if(textStatus == "error")
								mui.toast('请检查网络连接');
						  	}
					  	});
	
					} catch(e) {
					  mui.toast("请检查网络连接");
					
				   	}

				}								
			}
			
			
			/*
			 * 初始化上下拉加载
			 */
			mui.init({
		        pullRefresh: {
		          container: '#pullrefresh',
		          down: {
		            callback: pulldownRefresh,
		            auto: true
		          },
		          up: {
		            contentrefresh: '正在加载...',
		            callback: pullupRefresh,
		            auto: true
		          }
		        }
	      	});


			/*
			 * 请求数据
		 	*/
			function jiaohu() {

				var drugName = document.getElementById('searchInput').value;//输入框值
				var webUrl = XHDOC_WEBBASE + "dtcasehistory/getprofileDetails?&pageSize=10&name="+drugName+"&docguid="+XHDOC_APP_USRGUID+"&crtdat="+crtdat;
				
				if(crtdat != '' || drugName != ''){
					try {
					  	$.ajax({
						    url: webUrl,
						    type: "POST",
							async: false,
							dataType: "json",
							data: {
							  pageNo: count
							},
							success: function(data) {					
								totalNumber = Math.ceil(data.data.pageSize/10);//总条数
								console.log(data)
							  	try {
							  	
								    if(data.code == 000){
								    	arry = data.data;							    		
								    	
								    }else if(data.code == 001){
								    	mui.toast('请求出错'); 
								    }
		  
							  	} catch(e) {						    
								    mui.toast('获取数据失败'); 
							  	}
									
							},
							error: function(xhr, status, error) {						
						  		if(status == "error")
								mui.toast('获取数据失败');
						  	}		
					  	});
						
					} catch(e) {
					
					  mui.toast("请检查网络连接");
				   	}
				}

				
			};
	
	
			/**
			   * 下拉刷新具体业务实现
			*/
		  	function pulldownRefresh() {
		  		
		  		jiaohu();
		  		
			    setTimeout(function() {          
			      var table = document.body.querySelector('.mui-table-view');
			      var cells = document.body.querySelectorAll('.mui-table-view-cell');
			      for(var i = 0; i < arry.length; i++) {
			      	var dateTime = arry.parameterType[i].crtdat;
					var mydate = dateTime.substr(0,10); 
			        var li = document.createElement('li');
			        li.className = 'mui-table-view-cell mui-media mui-row';
					li.innerHTML = 
					            '<div name="'+arry.parameterType[i].zhand+'" class="name mui-col-sm-6 mui-col-xs-6">'+arry.parameterType[i].name+'</div>'+
					            '<div name="'+arry.parameterType[i].birthday+'" class="kaoheDate mui-col-sm-6 mui-col-xs-6">'+mydate+'</div>'+
					            '<div id="'+arry.parameterType[i].zhand+'" name="'+arry.parameterType[i].guid+'" class="viewRecord mui-col-sm-5 mui-col-xs-5">查看咨询建议</div>'+
					            '<div id="'+arry.parameterType[i].age+'" name="'+arry.parameterType[i].sex+'" class="sends mui-col-sm-3 mui-col-xs-3">发送</div>';								        
			      }
			      mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); //refresh completed
			
			    }, 1500);
		  	}
	
	
			/**
			   * 上拉加载具体业务实现
			*/
		  	function pullupRefresh() {

	  			jiaohu();
		        setTimeout(function() {
		          mui('#pullrefresh').pullRefresh().endPullupToRefresh((++count >= totalNumber+1)); //参数为true代表没有更多数据了。
		          var table = document.body.querySelector('.mui-table-view');
		          var cells = document.body.querySelectorAll('.mui-table-view-cell');		          
		          for(var i = 0, len = i + 10; i < len; i++) {
//		          	console.log(arry.parameterType[i].zhand)
		          	var dateTime = arry.parameterType[i].crtdat;
					var mydate = dateTime.substr(0,10); 
		            var li = document.createElement('li');
		            li.className = 'mui-table-view-cell mui-media mui-row';
					li.innerHTML = 
				             	'<div name="'+arry.parameterType[i].zhand+'" class="name mui-col-sm-6 mui-col-xs-6">'+arry.parameterType[i].name+'</div>'+
					            '<div name="'+arry.parameterType[i].birthday+'" class="kaoheDate mui-col-sm-6 mui-col-xs-6">'+mydate+'</div>'+
					            '<div id="'+arry.parameterType[i].zhand+'" name="'+arry.parameterType[i].guid+'" class="viewRecord mui-col-sm-5 mui-col-xs-5">查看咨询建议</div>'+
					            '<div id="'+arry.parameterType[i].age+'" name="'+arry.parameterType[i].sex+'" class="sends mui-col-sm-3 mui-col-xs-3">发送</div>';												
		            table.appendChild(li);
		          }
		
		        }, 1500);
		  	}
	
		  	if(mui.os.plus) {
		        mui.plusReady(function() {
		          	setTimeout(function() {
		            	mui('#pullrefresh').pullRefresh().pullupLoading();
		      		}, 1000);
		
		        });
		  	} else {
		        mui.ready(function() {
		          mui('#pullrefresh').pullRefresh().pullupLoading();
		        });
		  	}


			/*
			 * 查看咨询建议
			 */
			mui("body").on("tap", ".mui-table-view li .viewRecord", function() {
				var thisId = $(this).attr('name');
				showpage('view_medical_record.html?caseGuid='+thisId);
			})
			
			
			/*
			 * 发送病历
			 */
			mui("body").on("tap", ".mui-table-view li .sends", function() {
				var thisId = $(this).siblings('.viewRecord').attr('name');//guid
				var thisName = $(this).siblings('.name').html();//name
				var thisSex = $(this).attr('name');//sex
				var thisAge = $(this).attr('id');//age
				var thisZd = $(this).siblings('.viewRecord').attr('id');//诊断
//				console.log(thisId)
//				console.log(thisName)
//				console.log(thisSex)
//				console.log(thisAge)
//				console.log(thisZd)
//				showpage('view_medical_record.html?caseGuid='+thisId);
			})


			/*
			 * 返回用药方案页并传值
			 */
			try {
				
				if(XHDOC_BROWSETYPE == 'IOS') {
				
					//调用IOS的返回事件
					
				} else if(XHDOC_BROWSETYPE == 'ANDROID') {

					//调用ANDROID的返回事件

				}else{
					mui.back();
				}
	
			} catch(e) {
				console.log(e);
			}
			
		</script>
	</body>
</html>